package com.rookieci.totp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.rookieci.totp.R;

/**
 * Created by 磁磁帅 on 2025/8/10 0010.
 * 功能：
 */
public class QrCodeTextActivity extends Activity {
    private String codeTxt;
    private boolean openList;

    public static void open(Activity activity, String text) {
        open(activity, text, false);
    }

    public static void open(Activity activity, String text, boolean openList) {
        Intent intent = new Intent(activity, QrCodeTextActivity.class);
        intent.putExtra("text", text);
        intent.putExtra("openList", openList);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qrcode_text);
        Intent intent = getIntent();
        codeTxt = intent.getStringExtra("text");
        openList = intent.getBooleanExtra("openList", false);

        TextView text = findViewById(R.id.text);
        text.setText(codeTxt);
    }

    @Override
    public void finish() {
        if (openList) {//打开列表
            QrCodeListActivity.open(this);
        }
        super.finish();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.qrcode_text_menu, menu);
        return true;
    }

    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        if (item.getItemId() == R.id.navigation_scan) {//二维码展示
            QrCodeImageActivity.open(this, codeTxt);
        }
        return true;
    }

}
